#include<stdio.h>
#include<string.h>
#include<sys/wait.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/shm.h>
#define maxn 30
int main(){
	int shmid;//common-memory-flag
	char* pchar;
	char* addr;
	shmid=shmget((key_t)194,40,0666|IPC_CREAT);
	if(shmid == -1 )
	{
		perror("shmget failed\n");
		exit(-1);
	}
	//point connect memory
	addr=(char*)shmat(shmid,0,0);

	printf("addr 0x%p\n",addr);

 	pchar=addr;
	for(int i=0;i<26;i++) (*(pchar+i))=('A'+i);

	for(int i=0;i<26;i++) printf("%c",*(addr+i)); 
	printf("\n");
    	int x=fork();

	if(x==0){
	
 		pchar = addr;

	  	for(int i=0;i<26;i++){
			*(pchar+i)=('a'+i);
		}	
		exit(0);
	}
	else if(x>0){
		int status;
		wait(&status);
		for(int i=0;i<26;i++){
		    printf("%c",*(addr+i));
		}printf("\n");
		exit(0);
	}	
	return 0;
}

